package com.ktwlsoft.archivemanage.domain.business.repositoryService.study;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.entity.study.StudyClass;
import com.ktwlsoft.archivemanage.domain.dao.repository.study.StudyClassMapper;
import com.ktwlsoft.archivemanage.payload.study.studyClass.ClassManagePageRequest;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程
 *
 * @author Name on 2019/12/24 15:28
 * @version 1.0
 */
@Service
public class StudyClassRepositoryService {

    /**
     * 课程
     */
    @Getter
    private final StudyClassMapper studyClassMapper;

    public StudyClassRepositoryService(StudyClassMapper studyClassMapper) {
        this.studyClassMapper = studyClassMapper;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_class
     *
     * @mbg.generated
     */
    public int deleteByPrimaryKey(Long id) {
        return studyClassMapper.deleteByPrimaryKey(id);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_class
     *
     * @mbg.generated
     */
    public int insert(StudyClass record) {
        return studyClassMapper.insert(record);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_class
     *
     * @mbg.generated
     */
    public StudyClass selectByPrimaryKey(Long id) {
        return studyClassMapper.selectByPrimaryKey(id);
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_class
     *
     * @mbg.generated
     */
    public List<StudyClass> selectAll() {
        return studyClassMapper.selectAll();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table study_class
     *
     * @mbg.generated
     */
    public int updateByPrimaryKey(StudyClass record) {
        return studyClassMapper.updateByPrimaryKey(record);
    }

    /**
     * 通过banner呈现查询数据 on 2019/12/24 15:58
     *
     * @param bannerShow bannerShow
     * @return List<StudyClass>
     */
    public List<StudyClass> selectByBannerShow(Integer bannerShow, String type) {
        return studyClassMapper.selectByBannerShow(bannerShow, type);
    }

    /**
     * 根据num查询数据 on 2019/12/24 16:22
     *
     * @param num num
     * @return List<StudyClass>
     */
    public List<StudyClass> selectByLimitNum(Integer num, String type) {
        return studyClassMapper.selectByLimitNum(num, type);
    }

    /**
     * 分页 on 2019/12/24 16:57
     *
     * @param jsonObject jsonObject
     * @return PageInfo<StudyClass>
     */
    public PageInfo<StudyClass> findPage(int pn, int pageSize, JSONObject jsonObject) {
        PageHelper.startPage(pn, pageSize);
        return new PageInfo<>(studyClassMapper.findList(jsonObject));
    }

    /**
     * 热门课程分页 on 2019/12/24 17:37
     *
     * @param num num
     * @return PageInfo<StudyClass>
     */
    public PageInfo<StudyClass> moreHotsPage(int pn, int pageSize, Integer num, String type) {
        PageHelper.startPage(pn, pageSize);
        return new PageInfo<>(studyClassMapper.selectByLimitNum(num, type));
    }

    /**
     * 课程管理分页
     *
     * @param request
     * @return
     */
    public PageInfo<StudyClass> classManagePage(ClassManagePageRequest request) {
        PageHelper.startPage(request.getPn(), request.getPageSize());
        return new PageInfo<>(studyClassMapper.selectByConditons(request));
    }

    /**
     * 专题课程分页
     *
     * @param pn
     * @param pageSize
     * @param subjectId
     * @return
     */
    public PageInfo<StudyClass> selectBySubjectId(Integer pn, Integer pageSize, Long subjectId, String classType) {
        PageHelper.startPage(pn, pageSize);
        return new PageInfo<>(studyClassMapper.selectBySubjectId(subjectId, classType));
    }
}